1. Metasploit

“If I had eight hours to chop down a tree, I’d spend the first six of them sharpening my axe.”
-Abraham Lincoln

This saying is a constant reminder that approaching a problem with the right set of tools is critical for success.
Before approaching a penetration test or an audit, we always take care to “sharpen our tools” and update everything,especially the MSF.


Metasploit
It is a package of tools and utilities for penetration testing and security purposes.
It contains a wide array of commercial grade exploits and an extensive exploit development environment, network information gathering tools and web vulnerability plugins.

Vulnerability - A flaw in a piece of code that leaves a system open to risk.

Exploit - A vulnerability in a piece of software of which the attacker takes advantage of by performing appropriate actions.

Tip: Use metasploit in kali linux only since on windows your antivirus and firewall will keep nagging because of the exploits.

Metasploit architecture:

77aadbc548eea909ccbb01b53c045680.png

63ad41119ba337b4507a838c61b64a48.png

4f591f50d1b6c056dcc8a08c0a096703.png

Metasploit has multiple interfaces including;

  1. msfconsole - an interactive command-line like interface
  2. msfcli - a literal Linux command line interface
  3. Armitage - a GUI-based third party application
  4. msfweb - browser based interface

Metasploit has integrated a postgresql database to store the data collected from the scans and exploits.
With the help of the integrated tools the entire process of from port scanning, vulnerability scanning, exploitation and post-exploitation,can be done from metasploit.

Metasploit has 7 types of modules:

  1. exploits
  2. payloads
  3. auxiliary
  4. nops (No Operations)
  5. post (Post-exploitation)
  6. encoders
  7. evasion (Antivirus evasion module)

1f25c53da17394b4dc272c2a61fe24ef.png

eff9a3f2f971ee4ad5315a3479de7b26.png

387938cc1e5ac0af885879f271d5c151.png


Using Metasploit: Key console commands

The msfconsole is the most popular interface of the Metasploit Framework (MSF). It provides an “all-in-one” centralized console and allows you efficient access to virtually all of the options available in the MSF.

Benefits of Using MSFconsole

ad39b06917ffd05a2c5ae6c15c9ba8f8.png


msfconsole

The command prompt will change to ‘msf>’.

3d7036c6f4c929833455626eadc17a3a.png

msfconsole -q

Note: If you get ‘WARNING: No database support: No database YAML file’ message.
Then exit, and create database using ‘msfdb init’ command.

ec2f9ffa2434ffba948aa032e2908f6a.png

8149aa1e8eeee3f362f852421ad2a5ae.png

msfconsole -h

2d650a9fae93a95bf7cb2c43fcc7ccdb.png

msf>help

7106e87c30618b44c6742e8062e9d436.png

msf>db_status

347e6c37f7c9a39c40bbab8521ed478b.png

service postgresql start


Module Related Commands

Load a module

The "use" command loads a module (exploit,auxiliary etc).

msf > use [module]

For Ex: To load the ’exploit/windows/browser/adobe_flash_avm2’ module
(An exploit that takes advantage of one of the many vulnerabilities in the Adobe Flash plug-in),
enter:

msf > use exploit/windows/browser/adobe_flash_avm2

f230b55e1f339c4a5d0899566183b64c.png
Metasploit responds with type of module (exploit):module name(in red).

Show Command
Used after loading a module to get more information about it.

  1. msf>show options

This command is also very useful in running an exploit. It will display all of the options that need to set before running the module. Ex: IP addresses, URI path, the port, etc

73fb0e6bb400ad57d86e9c2b7cceb35f.png

  1. msf>show payloads

This command, when used after selecting your exploit, will show you all the payloads that are compatible with the exploit.

d75fd82679c01f3b2c3288b0f47d2c26.png

  1. msf>show targets

Each exploit has a list of the targets it will work against. It will show the list. Some exploits have as many as 100 different targets and success will often depend upon selecting the correct one. These targets can be defined by operating system, service pack and language, among other things.

377543897353d2fc5292bc521d2f5e1f.png

Info command

msf > info

This command will show key information about the module, including the options that need to be set, the amount of payload space and module’s description. It’s better to run it after selecting the exploit.

8b1253887fd0168bd056755b0f41d0a9.png

412ffd43ab3e3dfbadc6cf6ffa099f4a.png

Search Command
It is used to search for the right module.

9f02bc49a9b222157abc37972735a5b5.png

To be more specific we can use the following keywords:

Syntax:

msf>search keyword:value

For Ex: To search for an exploit (type) for Windows (platform) for Adobe Flash,enter:

msf > search type:exploit platform:windows flash_a

Or

Syntax:

msf>search keyword1:keyword2

msf > search exploit:windows flash_a

Metasploit will search it's database for modules that were exploits for the Windows platform and included the keyword "flash_a".

3ffec8128187205752a4808972de53da.png

Set command
It is used to set options within the selected module.

For Ex:

msf > set SRVPORT 80

This changes the default SVRPORT (server port) from 8080 to 80

To unset the option that was previously set.

msf > unset SRVPORT

46728447e4e6ebba881639e61e47fb6a.png

In many exploits, you will see the following options (variables).

Exploit or run command
You can use exploit or run command to launch a module against a target.

msf exploit(e_name)>exploit

After loading our exploit and setting all the necessary options we exploit.
This sends the exploit to the target system and, if successful, installs the payload.

b221edb0ba9c2f14640414de02574183.png
Above the exploit starts and is running as background job with a reverse handler on port 4444.
It then started a webserver on host 0.0.0.0 on port 80 with a randomized URL (F5pmyl9gCHVGw90).
You can chose a specific URL by specifying URIPATH variable with set command.

Back command

msf>back

To take us back one step and remove the loaded exploit.

b4085341fd75a73ccd240d374054d333.png

Exit msfconsole
Exits us from the msfconsole and back into the BASH command shell.

msf>exit

71e7bd42649d9b5d186acb5f371ac7be.png


The Ruby Interface

Metasploit is written ruby programming language. You can create your own custom ruby scripts in it.

msf>irb

b6af449686eaff6c3be989bc8283e6f8.png


Understanding Background Jobs

Jobs are modules that are running in the background. The jobs command provides the ability to list and terminate these jobs.

msf>jobs -h

msf>jobs -l

546bdaf90b2bd19b5f4b3efd38acb8d5.png

msf> job -k [PID]


Running NMAP inside the console

Command:

msf>db_nmap [OPTIONS] [TARGET]

804937cad36b5ef249d184274bd16c3e.png
To generate the three nmap output files (xml, grepable, and normal):

msf>db_nmap [OPTIONS] [TARGET] -oA [FILENAME]


Issuing Hosts command

A host refers to a device on a network and is represented by its IP address or server name. Hosts are typically fingerprinted, enumerated, and added to a project during a discovery scan, data import, or Nexpose scan.

07a91dfd41624923175ad6886ac78e5c.png

msf>hosts -h

a2aca076c8ac0013db23f70ef83b7761.png

The output at the bottom of above command will give us the list of columns in the database. It can help us in extracting specific host data from the database.

09d065835d868824ba9b8b14f5d4f252.png

msf>hosts -c [Column1] [Column2]...

msf>hosts -c address,os_family

c08779fe3c5995a0b3b756e6f976bc3c.png

To generate a CSV text file that contains the data from the host table use the hosts command and the -o option.
The data includes the IP address, MAC address, host name, operating system, OS flavor, purpose, and comments.

msf> hosts -o [FILENAME]


After scan Services stored in Database
Service command gives a list of services discovered and stored in the database from a prior scan.

msf>services [HOST ADDRESS]

1ac56b32546b538dc317cf98425fbe6d.png

To see service commands options

msf>services -h

9e963774874820bd42ebcb66315d54ba.png

To pull list of all services discovered for a host

msf>services -c name,info [HOST ADDRESS]

0765d54b26ee120ab781de32954fbadb.png


Loot
It is used to view hash dump (collected from target hosts) which is stored in our database.

msf> loot

0b0e01ccbe2f03223f73a38a3629f2a8.png

A few of the most popular hashing algorithms:

Hashing schemes now use a trick called "Salting", adding random data to a password before hashing it and then storing that "salt" value along with the hash.


Finding Credentials
The creds command is used to manage found and used credentials for targets in our database.

6ac6b6bbbb23a7505d22ba2beaeb9c05.png

Note: Offensive Security provides a free in depth course on metasploit- Metasploit Unleashed